 	function showTasks(){	
		affichage();
	for(var i=0;i<jeutest.length;i++){

				$('<tr id='+i+'>')
						.html("<td >"+jeutest[i].id+"</td><td>"+jeutest[i].resume+"</td><td>"+jeutest[i].statut+"</td><td>"+jeutest[i].priorite+"</td><td>"+jeutest[i].avancement+"</td><td>"+jeutest[i].assigne+"</td><td><a href=\"#\" id="+i+" class=\"popup\" ><img id="+i+" src =\"assets/images/edit.png\"/></a></td><td><a href=\"#\"><img class=\"delb\" id="+i+" src =\"assets/images/delete.png\"/></a></td>")
						.addClass('del')
						//.addclass('editb')
						.appendTo('tbody.tb');
			}	

			
			$('a.popup').click(function() {

        		$('#dialog').dialog('open');
    			$('#hide').val($(this).attr('id'));
				$('#resumem').val(jeutest[$(this).attr('id')].resume);
				$('#statutm').val(jeutest[$(this).attr('id')].statut);
				$('#prioritem').val(jeutest[$(this).attr('id')].priorite);
				$('#avancementm').val(jeutest[$(this).attr('id')].avancement);
				$('#assignem').val(jeutest[$(this).attr('id')].assigne);
			
        		// prevent the default action, e.g., following a link
       			 return false;
    		});
			$('.delb').click(function(){
				var answer = confirm("Etes vous sur ?")
				if (answer)
				{
				jeutest.splice($(this).attr('id'),1);
				showTasks();
				
				}
				else
				{
				}
				
				
			})

			$('.editb').click(function(){
				
				var resume = $('#resumem').val();
				var hide = $('#hide').val();
				var statut = $('#statutm').val();
				var priorite = $('#prioritem').val();
				var avancement = $('#avancementm').val();
				var assigne = $('#assignem').val();
				
				
				jeutest[hide].resume = resume;
				jeutest[hide].statut = statut;
				jeutest[hide].priorite = priorite;
				jeutest[hide].avancement = avancement;
				jeutest[hide].assigne = assigne;
				showTasks();
				
			})
			
	};

	function affichage(){
	$(".tb").children().each(function(){
		//remove les tr
		$('tr.del').remove();
	});

}

 $(document).ready(function () {
 	$("body").append('<div id="dialog" title="Popup"></div>');
		    $("#dialog").html('<FORM METHOD="POST" ACTION="#" class="jqtransform">Resume /Objet :<INPUT TYPE="texte" id="resumem" SIZE="30"><br /> Statut:<INPUT TYPE="texte" id="statutm" SIZE="30"><br />Priorite:<INPUT TYPE="texte" id="prioritem" SIZE="30"><br />avancement:<INPUT TYPE="texte" id="avancementm" SIZE="30"><br />Assigne:<INPUT TYPE="texte" id="assignem" SIZE="30"><input type="hidden" id="hide"></form><input class="editb" type="submit" value="Modifier">');
		    var $dialog = $('#dialog').dialog({
		            autoOpen: false,
		            title: 'Modification d une tache',
		            width: 500,
		            height: 300
		    })
		       $('.add').click(function(){
			
				var resume = $('#resume').val();
				var statut = $('#statut').val();
				var priorite = $('#priorite').val();
				var avancement = $('#avancement').val();
				var assigne = $('#assigne').val();

				
				var nbtache=jeutest.length+1; //
				var addtache = {"id" : nbtache, "resume": resume, "statut" : statut, "priorite" : priorite, "avancement" : avancement, "assigne" : assigne};
				jeutest.push(addtache);
				showTasks();
				
			})
	
});